package com.example.resourceSharingPlatform.controller;


import com.example.resourceSharingPlatform.entity.Account;
import com.example.resourceSharingPlatform.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AccountController {
    @Autowired
    private AccountService accountService;

    /**
     * 1.通过id查询账户信息 GET
     * ip:port/account?id=xx
     *
     * 2.新增账户 POST
     * ip:port/account
     * body中填写account类的信息
     *
     * 3.更新账户信息 PUT
     * ip:port/account
     * body中填写account类的信息
     *
     * 4.根据id删除账户 DELETE
     * ip:port/account?id=xx
     * */

    @GetMapping("/account")
    Account getAccountById(@RequestParam(value = "id")String id){
        return accountService.queryAccountById(id);
    }

    @PostMapping("/account")
    Account addAccount(@RequestBody Account account){
        return accountService.insertAccount(account);
    }

    @PutMapping("/account")
    boolean updateAccount(@RequestBody Account account){
        return accountService.updateAccount(account);
    }

    @DeleteMapping("/account")
    boolean deleteAccount(@RequestParam(value="id")String id){
        return accountService.deleteAccount(id);
    }
}
